import { Body, Controller, Post } from '@nestjs/common';
import {
  ApiOkResponse,
  ApiOperation,
  ApiSecurity,
  ApiTags,
} from '@nestjs/swagger';
import { SysMenuService } from './menu.service';
import { ADMIN_PREFIX } from '../../admin.constants';

@ApiSecurity(ADMIN_PREFIX)
@ApiTags('菜单模块')
@Controller('menu')
export class SysMenuController {
  constructor(private sysMenuService: SysMenuService) {}

  @ApiOperation({ summary: '初始化菜单' })
  @ApiOkResponse()
  @Post('initMenu')
  public async initMenu(@Body() list) {
    if (list && list.length) {
      await this.sysMenuService.removeAllMenu();

      await this.sysMenuService.addAllMenu(list);
    }
  }
}
